package middleware

import (
	"emailcenter/utils/logx"
	"emailcenter/utils/resx"
	"github.com/gin-gonic/gin"
)

func ErrorMiddleware() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		defer func() {
			err := recover()
			if err != nil {
				//if _, ok := err.(os.PathError); ok {
				//	// xxx
				//}
				logx.LogrusObj.Error(err)
				ctx.JSON(200, resx.GinResp(resx.SystemErr, nil))
				ctx.Abort()
			}
		}()
		ctx.Next()
	}
}
